package io;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

public class IODemo7 {
    public static void main(String[] args) throws IOException {
//        //打开文件
//        InputStream inputStream = null;
//        try {
//            inputStream = new FileInputStream("./test.txt");
//        }finally {
//            inputStream.close();
//        }


        //一旦出了try代码块, 此时try自动调用inputStream的close
        //实现了Closeable接口的类,才能放到try里面
        try(InputStream inputStream = new FileInputStream("./test.txt")){
            while(true) {
                byte[] buffer = new byte[1024];
                int x = inputStream.read();
                if(x == -1) {
                    //文件读取完毕了
                    break;
                }
                System.out.printf("%x ",x);
            }
        }

    }
}
